﻿using System;

namespace Program28
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(GetSum(1, 8));
            Console.WriteLine(GetSum(2, 3, 5, 8, 9, 10));
            Studen("罗本维", 0, 100, 100, 100);
        }

        /// <summary>
        /// params 可变数量参数
        /// (可嵌套泛型)
        /// </summary>
        /// <param name="n"></param>
        /// <returns></returns>
        public static int GetSum(params int[] n) 
        {
            var sum = 0;
            foreach (var item in n)
            {
                sum += item;
            }
            return sum;
        }
        public static void Print(params object[] obj) 
        {
            foreach (var item in obj)
            {
                Console.WriteLine(item);
            }
        }

        /// <summary>
        /// 可变参数要放在所以形参的末尾
        /// </summary>
        /// <param name="name"></param>
        /// <param name="id"></param>
        /// <param name="scores"></param>
        public static void Studen(string name, int id, params float[] scores) 
        {
            float sum = 0;
            float avg = 0;
            Console.Write("姓名:" + name + ",序号:" + id + ",");
            Console.Write("成绩:");
            foreach (var item in scores)
            {
                Console.Write(item + " ");
                sum += item;
            }
            avg = sum / scores.Length;
            Console.Write("平均分:{0},总成绩{1}",avg,sum);
        }
    }
}
